const joi = require('joi');
const validationMiddleware = require('../../middleware/validate');
const { dealNotEmpty } = require('../../utils/dberrordeal');
const GoodController = require('../../controllers/good/goodController');
const router = require('koa-router')();
router.prefix('/good');
const rulesSchema = {
    '/good/addgoods': joi.object({
        name: dealNotEmpty('商品名称'),
        price: dealNotEmpty('商品价格'),
        description: Joi.string().allow('').optional(),
        categoryId: dealNotEmpty('分类'),
        tagId: dealNotEmptyArry('标签'),
        isCouponAllowed: Joi.boolean().optional(),
        images: Joi.array().items(Joi.string()).optional(),
    }),
    '/good/putgoods': joi.object({
        id: dealNotEmpty('商品id'),
        name: dealNotEmpty('商品名称'),
        price: dealNotEmpty('商品价格'),
        description: Joi.string().allow('').optional(),
        categoryId: dealNotEmpty('分类'),
        tagId: dealNotEmptyArry('标签'),
        isCouponAllowed: Joi.boolean().optional(),
        images: Joi.array().items(Joi.string()).optional(),
    }),
    '/good/getgoods': joi.object({
        id: dealNotEmpty('商品id'),
    }),
    '/good/delgoods': joi.object({
        id: dealNotEmpty('商品id'),
    }),
}

router.post('/addgoods', validationMiddleware(rulesSchema), GoodController.createGoods);
router.post('/putgoods', validationMiddleware(rulesSchema), GoodController.updateGoods);
router.post('/getgoods', validationMiddleware(rulesSchema), GoodController.getGoodsById);
router.post('/delgoods', validationMiddleware(rulesSchema), GoodController.deleteGoods);
router.post('/getgoodslist', GoodController.getGoodsList);
module.exports = router;
